package com.internetCafes.spms.web.tenant.service.impl;

import com.internetCafes.spms.core.generic.GenericDao;
import com.internetCafes.spms.core.generic.GenericServiceImpl;
import com.internetCafes.spms.core.model.pageModel.DataGrid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.internetCafes.spms.web.tenant.dao.TenantRoleMenuInfoMapper;
import com.internetCafes.spms.web.tenant.model.TenantRoleMenuInfo;
import com.internetCafes.spms.web.tenant.service.TenantRoleMenuInfoService;


/**
 * 租户角色功能信息表 TenantRoleMenuInfoService 实现类
 *
 * @author Sunny
 * @email rekeeper2011@hotmail.com
 * @date 2019-10-31 18:09:54
 */
@Service("tenantRoleMenuInfoService")
public class TenantRoleMenuInfoServiceImpl extends GenericServiceImpl<TenantRoleMenuInfo, Long> implements TenantRoleMenuInfoService {

    @Autowired
    private TenantRoleMenuInfoMapper tenantRoleMenuInfoMapper;

    @Override
    public List<TenantRoleMenuInfo> query(Map<String, Object> params) {
        return tenantRoleMenuInfoMapper.selectByParams(params);
    }

    @Override
    public TenantRoleMenuInfo findById(Long id) {
        return tenantRoleMenuInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TenantRoleMenuInfo> queryByIds(List<Long> ids) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids);
        return tenantRoleMenuInfoMapper.selectByParams(params);
    }

    @Override
    public List<TenantRoleMenuInfo> page(Map<String, Object> params, int page, int rows) {
        params.put("page", page);
        params.put("rows", rows);
        return tenantRoleMenuInfoMapper.selectByParams(params);
    }

    @Override
    public long count(Map<String, Object> params) {
        return tenantRoleMenuInfoMapper.countByParams(params);
    }

    @Override
    public TenantRoleMenuInfo findFirst(Map<String, Object> params) {
        List<TenantRoleMenuInfo> list = tenantRoleMenuInfoMapper.selectByParams(params);
        TenantRoleMenuInfo tenantRoleMenuInfo =null;
        if (list != null && list.size() > 0) {
            tenantRoleMenuInfo =list.get(0);
        }
        return tenantRoleMenuInfo;
    }

    @Override
    public int save(TenantRoleMenuInfo tenantRoleMenuInfo) {
        return tenantRoleMenuInfoMapper.insert(tenantRoleMenuInfo);
    }

    @Override
    public int saveBatch(List<TenantRoleMenuInfo> tenantRoleMenuInfoList) {
        return tenantRoleMenuInfoMapper.insertBatch(tenantRoleMenuInfoList);
    }

    @Override
    public int saveSelective(TenantRoleMenuInfo tenantRoleMenuInfo) {
        return tenantRoleMenuInfoMapper.insertSelective(tenantRoleMenuInfo);
    }

    @Override
    public int update(TenantRoleMenuInfo tenantRoleMenuInfo) {
        return tenantRoleMenuInfoMapper.updateByPrimaryKey(tenantRoleMenuInfo);
    }

    @Override
    public int updateSelective(TenantRoleMenuInfo tenantRoleMenuInfo) {
        return tenantRoleMenuInfoMapper.updateByPrimaryKeySelective(tenantRoleMenuInfo);
    }

    @Override
    public int delete(Long id) {
        return tenantRoleMenuInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteBatch(List<Long> ids) {
        return tenantRoleMenuInfoMapper.deleteBatchByPrimaryKey(ids);
    }

    @Override
    public void deleteBatch(Long[] ids) {
        if(ids != null && ids.length > 0){
            for(Long id : ids){
                delete(id);
            }
        }
    }

    @Override
    public GenericDao<TenantRoleMenuInfo, Long> getDao() {
        return tenantRoleMenuInfoMapper;
    }

    /**
	 * DataGrid
	 */
    @Override
    public DataGrid dataGrid(Map<String, Object> params, int pageNo, int pageSize) {

        List<TenantRoleMenuInfo> tenantRoleMenuInfoList = page(params, (pageNo - 1 < 0 ? -1 : pageNo - 1) * pageSize, pageSize);
        long count = count(params);

        DataGrid dg = new DataGrid(tenantRoleMenuInfoList, count, pageSize, pageNo);
        return dg;
    }
}